package com.link.wseller.mapper;

import com.link.wseller.domain.OrderMaster;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface OrderMasterMapper {
    @Delete({
        "delete from order_master",
        "where order_id = #{orderId,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String orderId);

    @Insert({
        "insert into order_master (order_id, buyer_name, ",
        "buyer_phone, buyer_address, ",
        "buyer_openid, order_amount, ",
        "order_status, pay_status, ",
        "create_time, update_time)",
        "values (#{orderId,jdbcType=VARCHAR}, #{buyerName,jdbcType=VARCHAR}, ",
        "#{buyerPhone,jdbcType=VARCHAR}, #{buyerAddress,jdbcType=VARCHAR}, ",
        "#{buyerOpenid,jdbcType=VARCHAR}, #{orderAmount,jdbcType=DECIMAL}, ",
        "#{orderStatus,jdbcType=TINYINT}, #{payStatus,jdbcType=TINYINT}, ",
        "#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})"
    })
    int insert(OrderMaster record);

    @InsertProvider(type=OrderMasterSqlProvider.class, method="insertSelective")
    int insertSelective(OrderMaster record);

    @Select({
        "select",
        "order_id, buyer_name, buyer_phone, buyer_address, buyer_openid, order_amount, ",
        "order_status, pay_status, create_time, update_time",
        "from order_master",
        "where order_id = #{orderId,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="order_id", property="orderId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="buyer_name", property="buyerName", jdbcType=JdbcType.VARCHAR),
        @Result(column="buyer_phone", property="buyerPhone", jdbcType=JdbcType.VARCHAR),
        @Result(column="buyer_address", property="buyerAddress", jdbcType=JdbcType.VARCHAR),
        @Result(column="buyer_openid", property="buyerOpenid", jdbcType=JdbcType.VARCHAR),
        @Result(column="order_amount", property="orderAmount", jdbcType=JdbcType.DECIMAL),
        @Result(column="order_status", property="orderStatus", jdbcType=JdbcType.TINYINT),
        @Result(column="pay_status", property="payStatus", jdbcType=JdbcType.TINYINT),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP)
    })
    OrderMaster selectByPrimaryKey(String orderId);

    @UpdateProvider(type=OrderMasterSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(OrderMaster record);

    @Update({
        "update order_master",
        "set buyer_name = #{buyerName,jdbcType=VARCHAR},",
          "buyer_phone = #{buyerPhone,jdbcType=VARCHAR},",
          "buyer_address = #{buyerAddress,jdbcType=VARCHAR},",
          "buyer_openid = #{buyerOpenid,jdbcType=VARCHAR},",
          "order_amount = #{orderAmount,jdbcType=DECIMAL},",
          "order_status = #{orderStatus,jdbcType=TINYINT},",
          "pay_status = #{payStatus,jdbcType=TINYINT},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "update_time = #{updateTime,jdbcType=TIMESTAMP}",
        "where order_id = #{orderId,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(OrderMaster record);
}